package adc.budget.ui.web.wicket.category;

import org.apache.wicket.markup.html.form.ChoiceRenderer;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.Radio;
import org.apache.wicket.markup.html.form.RadioGroup;
import org.apache.wicket.markup.html.form.SimpleFormComponentLabel;
import org.apache.wicket.markup.html.form.TextArea;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.ResourceModel;

import adc.app.ui.wicket.BoEditPanel;
import adc.app.ui.wicket.model.DomainObjectListModel;
import adc.budget.spec.bo.ICategory;
import adc.budget.spec.bs.ICategoryBs;
import adc.budget.ui.web.wicket.IMsgsMisc;

public class CategoryEditPanel extends BoEditPanel<ICategory> {

    private static final long serialVersionUID = 1L;

    public CategoryEditPanel(String id) {
        super(id);
    }

    @Override
    protected void addFields(Form<ICategory> form) {
        final TextField<String> tfName = new TextField<String>("name");
        tfName.setLabel(new ResourceModel(IMsgsMisc.NAME));
        form.add(new SimpleFormComponentLabel("nameLbl", tfName)).add(tfName);

        final DropDownChoice<ICategory> ddlParent = new DropDownChoice<ICategory>("parent",
                new DomainObjectListModel<ICategory>(ICategoryBs.class), new ChoiceRenderer<ICategory>("name", "id"));
        ddlParent.setLabel(new ResourceModel(IMsgsMisc.PARENT));
        form.add(new SimpleFormComponentLabel("parentLbl", ddlParent)).add(ddlParent);

        final TextArea<String> taNotes = new TextArea<String>("notes");
        taNotes.setLabel(new ResourceModel(IMsgsMisc.NOTES));
        form.add(new SimpleFormComponentLabel("notesLbl", taNotes)).add(taNotes);

        final RadioGroup<Boolean> rgIncome = new RadioGroup<Boolean>("income");
        rgIncome.setLabel(new ResourceModel(IMsgsMisc.TYPE));
        form.add(new SimpleFormComponentLabel("incomeLbl", rgIncome)).add(rgIncome);

        final Radio<Boolean> rdIncome = new Radio<Boolean>("optIncome", Model.of(Boolean.TRUE));
        rdIncome.setLabel(new ResourceModel(IMsgsMisc.INCOME));
        rgIncome.add(new SimpleFormComponentLabel("optIncomeLbl", rdIncome)).add(rdIncome);
        
        final Radio<Boolean> rdExpense = new Radio<Boolean>("optExpense", Model.of(Boolean.FALSE));
        rdExpense.setLabel(new ResourceModel(IMsgsMisc.EXPENSE));
        rgIncome.add(new SimpleFormComponentLabel("optExpenseLbl", rdExpense)).add(rdExpense);

    }
}
